<?php
final class Embedmedia 
{
    private static $providers = array('soundcloud' => 'Provider_Soundcloud',
                                      'vimeo'      => 'Provider_Vimeo',
                                      'youtube'    => 'Provider_Youtube',
                                      'slideshare' => 'Provider_Slideshare');
            
    public static function factory($link)
    {
  
        if($host = parse_url($link,PHP_URL_HOST))
        {
            $host_names = explode(".", $host);
            $host = $host_names[count($host_names)-2];
            
            if(isset(self::$providers[$host]))
            {
                return new self::$providers[$host]($link);
            }
            elseif(in_array(mb_strtolower(pathinfo(parse_url($link,PHP_URL_PATH),PATHINFO_EXTENSION)),
                   array('doc','docx','xls','xlsx','ppt','pttx','pdf','psd','dxf')))
            {
                return new Provider_File($link);
            }
        }
      
        return false; 

    }
    
}
?>
